package com.solotiger.douban.biz;

import android.util.Log;

import com.solotiger.douban.biz.event.BaseEvent;
import com.solotiger.douban.common.EventContants;
import com.solotiger.douban.exception.ResultException;
import com.solotiger.douban.util.LogUtils;
import com.solotiger.douban.util.RxBus;

import java.net.UnknownHostException;

import io.reactivex.observers.DisposableObserver;
import retrofit2.HttpException;

public abstract class BaseSubscriber<T> extends DisposableObserver<T> {

    @Override
    public void onError(Throwable e) {
        if (e instanceof ResultException) {    //服务器返回的错误
            LogUtils.e("ResultException", Log.getStackTraceString(e));
        } else if (e instanceof HttpException) {

        } else if (e instanceof UnknownHostException) {
            RxBus.INSTANCE.send(new BaseEvent(EventContants.ERROR_NETWORK));
        }
        _onError(e);

    }

    /**
     * 这个其实就是默认的onError错误回调,因为默认的被我们处理了
     *
     * @param e
     */
    protected abstract void _onError(Throwable e);

    @Override
    public void onComplete() {
        //empty
    }
}
